#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
const int N = 2010;


void solve()
{
    int n, m, k;
    cin >> n >> m >> k;
    map<int, int> mp, mp2;
    bool ok = true;
    for(int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if(x <= k) mp[x]++;
    }
    int s = mp.size();
    if(s < k / 2) ok = false;
    int t = 0;
    for(int i = 0; i < m; i++) {
        int x;
        cin >> x;
        if(x <= k){
            if(mp[x]++ == 0) t++;
            mp2[x]++;
        }
    }
    if(k - s > t || mp2.size() < k / 2) ok = false;
    if(ok) cout << "YES\n";
    else cout << "NO\n";
    
}

int main()
{
    int t = 1;
    cin >> t;
    while (t--)
        solve();
    return 0;
}